package cn.iocoder.yudao.module.tms.controller.admin.accountperiodtodo;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.tms.controller.admin.accountperiodtodo.vo.*;
import cn.iocoder.yudao.module.tms.service.accountperiodtodo.AccountPeriodTodoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.*;


import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 账期待办事项 Controller
 *
 * @author 芋道源码
 */
@Tag(name = "管理后台 - 账期待办事项")
@RestController
@RequestMapping("/tms/account-period-todo")
@Validated
public class AccountPeriodTodoController {

    @Resource
    private AccountPeriodTodoService accountPeriodTodoService;

    @GetMapping("/page")
    @Operation(summary = "获得账期待办事项分页")
    @PreAuthorize("@ss.hasPermission('tms:account-period-todo:query')")
    public CommonResult<PageResult<AccountPeriodTodoRespVO>> getAccountPeriodTodoPage(
            @Valid AccountPeriodTodoPageReqVO pageReqVO) {
        PageResult<AccountPeriodTodoRespVO> pageResult = accountPeriodTodoService.getAccountPeriodTodoPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/get")
    @Operation(summary = "获得账期待办事项")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('tms:account-period-todo:query')")
    public CommonResult<AccountPeriodTodoRespVO> getAccountPeriodTodo(@RequestParam("id") Long id) {
        AccountPeriodTodoRespVO todo = accountPeriodTodoService.getAccountPeriodTodo(id);
        return success(todo);
    }

    @PutMapping("/complete")
    @Operation(summary = "完成待办事项")
    @PreAuthorize("@ss.hasPermission('tms:account-period-todo:update')")
    public CommonResult<Boolean> completeTodo(@Valid @RequestBody CompleteTodoReqVO reqVO) {
        accountPeriodTodoService.completeTodo(reqVO.getId(), reqVO.getRemark());
        return success(true);
    }

    @PutMapping("/cancel")
    @Operation(summary = "取消待办事项")
    @PreAuthorize("@ss.hasPermission('tms:account-period-todo:update')")
    public CommonResult<Boolean> cancelTodo(@Valid @RequestBody CancelTodoReqVO reqVO) {
        accountPeriodTodoService.cancelTodo(reqVO.getId(), reqVO.getReason());
        return success(true);
    }

    @PutMapping("/batch-complete")
    @Operation(summary = "批量完成待办事项")
    @PreAuthorize("@ss.hasPermission('tms:account-period-todo:update')")
    public CommonResult<Boolean> batchCompleteTodo(@Valid @RequestBody BatchCompleteTodoReqVO reqVO) {
        accountPeriodTodoService.batchCompleteTodo(reqVO.getIds(), reqVO.getRemark());
        return success(true);
    }

    @GetMapping("/statistics")
    @Operation(summary = "获得待办统计")
    @PreAuthorize("@ss.hasPermission('tms:account-period-todo:query')")
    public CommonResult<AccountPeriodTodoStatisticsRespVO> getStatistics() {
        AccountPeriodTodoStatisticsRespVO statistics = accountPeriodTodoService.getStatistics();
        return success(statistics);
    }

    @GetMapping("/my-count")
    @Operation(summary = "获得我的待办数量")
    public CommonResult<Integer> getMyTodoCount() {
        Integer count = accountPeriodTodoService.getMyTodoCount();
        return success(count);
    }
}
